﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.EndItem.CApEITExposeEndItemDescendantsEnabler
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System.Collections.ObjectModel;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands.EndItem;

internal class CApEITExposeEndItemDescendantsEnabler : ITxCommandEnabler
{
  private bool CheckEnable()
  {
    bool flag = false;
    TxObjectList selectedEndItems = CApEITEndItemApp.GetSelectedEndItems();
    if (((Collection<ITxObject>) selectedEndItems).Count > 0)
      flag = this.IsValidSelection(selectedEndItems);
    return flag;
  }

  protected virtual bool IsValidSelection(TxObjectList objects)
  {
    bool flag = false;
    foreach (ITxEndItemProvider itxEndItemProvider in (Collection<ITxObject>) objects)
    {
      if (itxEndItemProvider.EndItemRepresentation is ITxEndItemRoot itemRepresentation && !itemRepresentation.IsDescendantsExposed)
      {
        if (itxEndItemProvider is ITxComponent itxComponent)
        {
          if (itxComponent != null)
          {
            if (itxComponent.IsEquipment)
            {
              if (itxComponent.IsOpenForModeling)
                break;
            }
            else
              break;
          }
          else
            break;
        }
        flag = true;
        break;
      }
    }
    return flag;
  }

  public bool Enable => this.CheckEnable();
}
